<template>
	<view class="content" >
		<view class="logo-group-view">
			<image :src="baseImageUrl+'/login/logo.png'"></image>
		</view>
		<view @tap="logoutAction()" class="logout-btn">退出登录</view>
		
		<view class="sync" @click="syncData">同步数据</view>
		
		<uniPopup ref="showAgainPop" type="center" style="z-index: 9991;position: fixed;top: --window-top;left: 0;">
			<view class="pop-group"> 
				<text class="pop-title">退出登录</text>
				<text class="pop-content">请确认是否退出账号</text>
				<view style="display: flex;width: 100%;">
					<view class="pop-btn-cancel" @click="cancelClick()">取消操作</view>
					<view class="pop-btn-sure" @click="confirmClick()">退出登录</view>
				</view>
			</view>
		</uniPopup>
	</view>
</template>

<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue';
	import configUrls from '@/common/config.js';
	export default {
		data() {
			return {
				baseImageUrl: configUrls.baseImageUrl,
				avatar:"",
				nickName:"微信用户",
			}
		},
		components:{
			uniPopup
	    },
		onLoad() {
	        const userInfoTemp = uni.getStorageSync("userInfo");
	        this.avatar = userInfoTemp.avatar
			this.nickName = userInfoTemp.nickName
		},
		methods: {
			syncData:function(){
				this.$Request.postParamsLoadView(configUrls.syncOrder,{day:2}).then(res=>{
					wx.showToast({
						title:'申请成功..请稍等再看',
						icon:'none'
					})
				})
			},
			logoutAction:function(){
				this.$nextTick(() => {
				    this.$refs['showAgainPop'].open();
				})
			},
			confirmClick:function(){
				let that = this;
				this.$Request.postJsonLoadView(configUrls.logout, {
				}).then(res => {
					if (res.code == "10000") {
						uni.removeStorageSync("userInfo");
						uni.removeStorageSync("accessToken");
						uni.removeStorageSync("userId");
						uni.removeStorageSync("expireTime");
						uni.setStorageSync("isLogin", false);
						uni.switchTab({
							url: '/pages/main/main',
							success: res => {},
							fail: () => {},
							complete: () => {}
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				}); 
			},
			cancelClick:function(){
				this.$nextTick(() => {
				    this.$refs['showAgainPop'].close();
				})
			},
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		background-color: #FFFFFF;
		width: 100vw;
		height: 100vh;
	}
	.logo-group-view {
		width: 100vw;
		height: 100vw;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.logo-group-view image {
		width: 210rpx;
		height: 198rpx;
	}
	.logout-btn{
		margin-left: 50rpx;
		margin-right: 50rpx;
		margin-top: 160rpx;
		background: linear-gradient(138deg, #F7CB47 0%, #D4CE4E 100%);
		border-radius: 88rpx;
		line-height: 88rpx;
		text-align: center;
		font-size: 32rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
	}
	.pop-group {
		background-color: #FFFFFF;
		border-radius: 20rpx;
		width: 580rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.pop-title {
		line-height: 108rpx;
		text-align: center;
		color: #333333;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 600;
	}
	.pop-content {
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #666666;
	}
	.pop-btn-cancel {
		font-size: 28rpx;
		font-family: MiSans-Regular, MiSans;
		font-weight: 400;
		color: #666666;
		text-align: center;
		line-height: 64rpx;
		border-radius: 10rpx;
		background-color: #F5F5F5;
		flex: 1;
		margin-left: 50rpx;
		margin-top: 40rpx;
		margin-bottom: 40rpx;
	}
	.pop-btn-sure {
		font-size: 28rpx;
		font-family: MiSans-Regular, MiSans;
		font-weight: 400;
		color: #FFFFFF;
		text-align: center;
		line-height: 64rpx;
		margin-left: 24rpx;
		background: linear-gradient(138deg, #F7CB47 0%, #C2CF51 100%);
		border-radius: 10rpx;
		flex: 1;
		margin-right: 50rpx;
		margin-top: 40rpx;
		margin-bottom: 40rpx;
	}
	.sync{
		
		font-size: 30rpx;
		text-align: center;
		color: red;
		margin-top: 60rpx;
	}
</style>
